#ifndef __LINKERSET__HH
#define __LINKERSET__HH

#include "types.h"

#if defined(__arm__) || defined( __ARMCC_VERSION )
#define CTD_LINKERSET_START(name) \
    Image$$##name##$$Base
#define CTD_LINKERSET_END(name) \
    Image$$##name##$$Limit
#else
#define CTD_LINKERSET_START(name) \
    _ctd_linkerset_##name##_start
#define CTD_LINKERSET_END(name) \
    _ctd_linkerset_##name##_end
#endif

#define CTD_LINKERSET_TABLESIZE(name) \
    ( (u32) (&CTD_LINKERSET_END(name)) - ((u32)(&CTD_LINKERSET_START(name))) )


#if defined(__arm__) || defined( __ARMCC_VERSION )
#define CTD_LINKERSET_DECLARE(name, type) \
    extern const type const CTD_LINKERSET_START(name); \
    extern const type const CTD_LINKERSET_END(name);
#else
#define CTD_LINKERSET_DECLARE(name, type) \
    extern const type const CTD_LINKERSET_START(name) CTD_SECTION(".ctd" #name); \
    extern const type const CTD_LINKERSET_END(name) CTD_SECTION(".ctd" #name);
#endif

#define CTD_LINKERSET_DEFINE(name, type) \
const type _ctd_linkerset_##type##_##name[] \
    CTD_ALIGN(4) \
    CTD_SECTION(".ctd." #type "." #name) \
    CTD_USED

#define CTD_LINKERSET_FOREACH(name, item) \
    for( \
    item = (name *)(&CTD_LINKERSET_START(name)); \
    item < (name *)(&CTD_LINKERSET_END(name)); \
    item ++ )

#endif